package lp.xian.materials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.materials.vo.PurchaseVo;
import lp.xian.materials.vo.QualityVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.materials.domain.Quality;
import lp.xian.materials.service.IQualityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 质检管理Controller
 *
 * @author ruoyi
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/quality/quality")
public class QualityController extends BaseController
{
    @Autowired
    private IQualityService qualityService;

    /**
     * 审批采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:audit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditQuality(@RequestBody QualityVo qualityVo) {
        return toAjax(qualityService.auditQuality(qualityVo));
    }

    /**
     * 查询质检管理列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:list')")
    @GetMapping("/list")
    public TableDataInfo list(Quality quality)
    {
        startPage();
        List<Quality> list = qualityService.selectQualityList(quality);
        return getDataTable(list);
    }

    /**
     * 导出质检管理列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:export')")
    @Log(title = "质检管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Quality quality)
    {
        List<Quality> list = qualityService.selectQualityList(quality);
        ExcelUtil<Quality> util = new ExcelUtil<Quality>(Quality.class);
        util.exportExcel(response, list, "质检管理数据");
    }

    /**
     * 获取质检管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:query')")
    @GetMapping(value = "/{qualityId}")
    public AjaxResult getInfo(@PathVariable("qualityId") Integer qualityId)
    {
        return success(qualityService.selectQualityByQualityId(qualityId));
    }

    /**
     * 新增质检管理
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:add')")
    @Log(title = "质检管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Quality quality)
    {
        return toAjax(qualityService.insertQuality(quality));
    }

    /**
     * 修改质检管理
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:edit')")
    @Log(title = "质检管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Quality quality)
    {
        return toAjax(qualityService.updateQuality(quality));
    }

    /**
     * 删除质检管理
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:remove')")
    @Log(title = "质检管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{qualityIds}")
    public AjaxResult remove(@PathVariable Integer[] qualityIds)
    {
        return toAjax(qualityService.deleteQualityByQualityIds(qualityIds));
    }
}
